#include <iostream>
#include <string>

using namespace std;

class Solution {
public:
    bool is_char(const char& ch)
    {
        if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
            return true;
        else
            return false;
    }
    string reverseOnlyLetters(string s) {
        int start=0;
        int end=s.size()-1;
        while(start<end)
        {
            while(start<end&&!is_char(s[start]))
                start++;
            while(start<end&&!is_char(s[end]))
                end--;
            swap(s[end],s[start]);
            end--;
            start++;
        }
       return s;
    }
};